
package com.kugou.game.sdk.adapter;

import com.kugou.framework.v4.Fragment;
import com.kugou.framework.v4.FragmentManager;
import com.kugou.framework.v4.FragmentStatePagerAdapter;

import android.view.ViewGroup;

import java.util.ArrayList;

/**
 * 描述:通用Viewpager的适配器
 * 
 * @author littlechuanxia
 * @since 2015年3月28日 下午3:44:35
 */
public class CommonViewPagerAdapter extends FragmentStatePagerAdapter {

    private String[] mTitles;

    private ArrayList<Fragment> mFragments;

    public CommonViewPagerAdapter(FragmentManager fm) {
        super(fm);
    }

    public void setFragments(ArrayList<Fragment> fragments, String[] titles) {
        mFragments = fragments;
        mTitles = titles;
    }

    @Override
    public Fragment getItem(int arg0) {
        if (mFragments != null && mFragments.size() > 0) {
            return mFragments.get(arg0);
        }
        return null;
    }

    @Override
    public int getCount() {
        if (mFragments != null) {
            return mFragments.size();
        } else {
            return 0;
        }
    }

    public String getPageTitle(int index) {
        if (mTitles != null && index < mTitles.length) {
            return mTitles[index];
        }

        return "";
    }

    /**
     * 重写此方法，不做实现，可防止子fragment被回收
     */
    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {

    }
}
